/*
** graph_action.c for zappy in /home/guidet_m/TECK2/projets/zappy/server_zappy
** 
** Made by michael guidet
** Login   <guidet_m@epitech.net>
** 
** Started on  Mon Jul  4 15:38:00 2011 michael guidet
** Last update Tue Jul  5 09:59:03 2011 michael guidet
*/

#include "server.h"

void		sendbct(t_fd *fd, t_env *e)
{
  int		y;
  int		x;
  char		cmd2[BUF_SIZE];

  for (y = 0; y < e->height; y++)
    for (x = 0; x < e->width; x++)
      {
	sprintf(cmd2, "bct %d %d %d %d %d %d %d %d %d\n", x, y,
		e->map[y][x].ressource[NOURRITURE], e->map[y][x].ressource[LINEMATE],
		e->map[y][x].ressource[DERAUMERE], e->map[y][x].ressource[SIBUR],
		e->map[y][x].ressource[MENDIANE], e->map[y][x].ressource[PHIRAS],
		e->map[y][x].ressource[THYSTAME]);
	add_string_to_list(&fd->send_list, cmd2);
      }
}

void		sendtna(t_fd *fd, t_env *e)
{
  int		i;
  char		cmd2[BUF_SIZE];

  for (i = 0; e->teams[i].name; i++)
    {
      sprintf(cmd2, "tna %s\n", e->teams[i].name);
      add_string_to_list(&fd->send_list, cmd2);
    }
}

void		sendpnw(t_fd *fd, t_env *e)
{
  int		temppos;
  t_fd		*tmp;
  char		cmd2[BUF_SIZE];

  for (tmp = e->fd; tmp; tmp = tmp->next)
    {
      if (tmp->type == AI)
	{
	  temppos = (tmp->pl->look_at == NORD) ? 1 :
	    (tmp->pl->look_at == EST) ?
	    2 : (tmp->pl->look_at == SUD) ? 3 : 4;
	  sprintf(cmd2, "pnw %d %d %d %d %d %s\n", tmp->pl->id,
		  tmp->pl->x,
		  tmp->pl->y,
		  temppos,
		  tmp->pl->level,
		  tmp->pl->team);
	  add_string_to_list(&fd->send_list, cmd2);
	}
    }
}

void		sendenw(t_fd *fd, t_env *e)
{
  char		cmd2[BUF_SIZE];
  int		i;
  t_egg		*mp;

  for (i = 0 ; e->teams[i].name; i++)
    {
      for (mp = e->teams[i].eggs; mp; mp = mp->next)
	{
	  sprintf(cmd2, "enw %d %d %d %d\n", mp->id, mp->id, mp->x, mp->y);
	  add_string_to_list(&fd->send_list, cmd2);
	}
    }
}
